Repository navigation
feat(view): add view metadata types and validation - #1069
kamcheungting-db wants to merge 5 commits into
Conversation
Deliver the view format v1 metadata model beside its table equivalent: - ViewVersion carries version-id, schema-id, timestamp-ms, summary, representations, optional default catalog, and required default namespace. - Representations are SQL (sql, dialect) or opaque unknown types preserved for round trips, modeled as a variant with GetSql and RepresentationType helpers. - ViewMetadata carries view-uuid, format-version, location, schemas, current-version-id, versions, version-log, and properties, with CurrentVersion/VersionById/CurrentSchema/SchemaById accessors returning NotFound for missing entries. - Validate() checks view-v1 invariants without applying table-format schema restrictions: supported format version, non-empty UUID/location, listed schemas/versions with unique IDs, current-version and schema references, non-empty default namespaces, non-empty SQL representations with at most one per dialect under ASCII case folding, and non-empty unknown representation types. - Add StringUtils::EqualsIgnoreCaseAscii for the ASCII-only dialect folding; existing Unicode-aware EqualsIgnoreCase is unchanged. - view_metadata_test validates synthetic metadata: every invariant violated one at a time with asserted error kinds, accepted shapes including unknown representations, accessor NotFound behavior, and equality.
52f0e84 to
ff317b3
Compare
|
Could you help me review this first PR of view? |
| /// \return the SQL representation, or nullptr when the representation is not | ||
| /// a SQL representation. The pointer remains valid until the representation | ||
| /// is modified or destroyed. | ||
| ICEBERG_EXPORT const SqlViewRepresentation* GetSql(const ViewRepresentation& repr); |
There was a problem hiding this comment.
Passing a named SQL alternative implicitly creates a temporary variant. The pointer returned by GetSql dangles at the end of the statement. Please reject temporary variants in both borrowing helpers.
| static constexpr int8_t kSupportedViewFormatVersion = 1; | ||
|
|
||
| /// An integer version number for the view format; must be 1. | ||
| int8_t format_version; |
There was a problem hiding this comment.
Please default-initialize the scalar members. A default-constructed ViewMetadata reads an indeterminate format version on its first call to Validate().
| return Invalid("View version {} references unlisted schema ID {}", | ||
| version->version_id, version->schema_id); | ||
| } | ||
| if (version->default_namespace.levels.empty()) { |
There was a problem hiding this comment.
Java can write an empty default namespace as []. Please allow that value and change the existing test to cover it.
| if (schema == nullptr) { | ||
| return Invalid("View schemas must not be null"); | ||
| } | ||
| if (!schema_ids.insert(schema->schema_id()).second) { |
There was a problem hiding this comment.
A view schema with duplicate field IDs passes this check and then fails on field lookup. Please validate field ID uniqueness independently of table format-version restrictions.
| dialects.push_back(sql->dialect); | ||
| } else { | ||
| const auto& unknown = std::get<UnknownViewRepresentation>(repr); | ||
| if (unknown.type.empty()) { |
There was a problem hiding this comment.
An unknown representation tagged sql passes validation without a query or dialect. Please reserve the SQL discriminator for the SQL alternative, including the case variants recognized by Java.
| return Invalid("Unsupported view format version: {}", | ||
| static_cast<int>(format_version)); | ||
| } | ||
| if (view_uuid.empty()) { |
There was a problem hiding this comment.
A non-empty string such as x passes as a view UUID. Please validate it with the existing UUID parser and return kInvalid for malformed values.
| version->version_id); | ||
| } | ||
| for (const auto& dialect : dialects) { | ||
| if (StringUtils::EqualsIgnoreCaseAscii(dialect, sql->dialect)) { |
There was a problem hiding this comment.
Java treats Éngine and éngine as the same dialect. Please normalize each dialect before inserting it into a set and cover this pair in the duplicate-dialect test.
| util/url_encoder.cc | ||
| util/uuid.cc) | ||
| util/uuid.cc | ||
| view_metadata.cc |
There was a problem hiding this comment.
I would suggest adding a view subdirectory.
| class SnapshotSummaryBuilder; | ||
|
|
||
| /// \brief View metadata. | ||
| struct SqlViewRepresentation; |
There was a problem hiding this comment.
Move them to view/type_fwd.h after the subdir is created.
…ation - Move view metadata and version sources and headers into a view subdirectory with its own type_fwd.h. - Reject temporary variants in GetSql and RepresentationType. - Default-initialize scalar members of view metadata, versions, and history entries. - Accept an empty default namespace, as Java writes it. - Reject duplicate field IDs in view schemas. - Reserve the SQL representation type for SQL representations, including Java's case-insensitive variants. - Validate view UUIDs with the UUID parser. - Normalize SQL dialects with Unicode case folding before checking for duplicates. Co-authored-by: Isaac <[email protected]>
What this PR does
Adds the Iceberg view format v1 metadata model — the first step of view support. It provides the types, validation, and lookup helpers for view definitions and their history. JSON serialization and catalog integration follow in later PRs.
The metadata model
All types compare by value.
Validation
ViewMetadata::Validate()returns the first violated invariant asErrorKind::kInvalidand leaves the metadata unchanged:schemasandversionswith unique, non-null IDs.version_logentry references a listed version.View schemas are validated independently of table-format schema restrictions, so projections keep the types and nullability of referenced columns.
CurrentVersion(),VersionById(),CurrentSchema(), andSchemaById()return the matching non-null entry, orErrorKind::kNotFoundwhen it is absent.The change also adds
StringUtils::EqualsIgnoreCaseAsciifor dialect matching and registers the new sources, tests, and public headers with the build and the C++20 compatibility check.Follow-ups
JSON serialization, preserving unknown representation payloads, metadata updates, and requirements.
Tests
view_metadata_test— 26 tests: valid metadata, multiple versions and dialects, unknown representation types, every validation failure with an asserted error kind (includingversion_logentries that reference unlisted versions), missing-entry lookups, equality, and representation helpers.Validated locally: all 26 view tests pass with ASAN + UBSAN + leak detection,
pre-commitis clean, andclang-tidy 22.1.8(the version CI pins) reports no findings on changed lines.